package com.yc.io.ftp;

import cn.hutool.extra.ssh.JschRuntimeException;
import cn.hutool.extra.ssh.Sftp;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
import com.jcraft.jsch.SftpProgressMonitor;

import java.io.InputStream;
import java.nio.charset.Charset;

/**
 * author: yc
 * description: 封装hutool的sftp
 * date: 2021/12/29 17:32
 */
public class MySftp extends Sftp {
    public MySftp(String sshHost, int sshPort, String sshUser, String sshPass) {
        super(sshHost, sshPort, sshUser, sshPass);
    }

    public MySftp(String sshHost, int sshPort, String sshUser, String sshPass, Charset charset) {
        super(sshHost, sshPort, sshUser, sshPass, charset);
    }

    public MySftp(Session session) {
        super(session);
    }

    public MySftp(Session session, Charset charset) {
        super(session, charset);
    }

    public MySftp(ChannelSftp channel, Charset charset) {
        super(channel, charset);
    }


    public Sftp myput(InputStream src, String destPath, SftpProgressMonitor monitor, Mode mode) {
        try {
            getClient().put(src, destPath, monitor, mode.ordinal());
        } catch (SftpException e) {
            throw new JschRuntimeException(e);
        }
        return this;
    }

}
